import supe from '../super.js';

export default class extends supe {
    render() {
        this.node.html(`
        <div style="margin:50px auto;">
        <form class="layui-form" action="">
  <div class="layui-form-item">
    <label class="layui-form-label">账户</label>
    <div class="layui-input-inline">
      <input type="text" name="title" required  lay-verify="required" placeholder="请输入账户" autocomplete="off" class="layui-input" id="user">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">密码</label>
    <div class="layui-input-inline">
      <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input" id="pwd">
    </div>
  </div>
    <div class="layui-form-item">
    <div class="layui-input-block">
      <button type="button" class="layui-btn" lay-submit lay-filter="formDemo" id="userBtn">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
  </div>
</form>  
        `)
    }
    handle() {
        layui.use('layer', function rem() {
            var layer = layui.layer;
            $('#userBtn').on('click', async function () {
                await $.ajax({
                    type: 'post',
                    url: '/login/addlog/' + $('#user').val() + '/' + $('#pwd').val(),
                    dataType: 'json',
                    success: (data) => {
                        data ? layer.msg(`注册成功`) : layer.msg(`注册失败`);
                    }
                })
                $('#user').attr('value', 'ww');
                $('#pwd').attr('value', 'www');
            })
        })
    }
}